package com.heima.admin.controller;

import com.heima.admin.service.ChannelService;


import com.heima.model.admin.dto.ChannelDTO;
import com.heima.model.admin.pojo.AdChannel;
import com.heima.model.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
//   @Validated({ValidatorAdd.class})   @Validated({ValidatorUpdate.class})
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理controller", tags = "频道管理controller", description = "频道管理controller")
public class ChannelController {
    @Autowired
    private ChannelService service;

    @ApiOperation("条件分页查询频道列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelDTO dto) {
        return service.findByQueue(dto);
    }

    @ApiOperation(value = "添加频道列表", notes = "添加时  会校验:频道名称不能为空,频道名称不能大于10个字符,频道名称不能重复")
    @PostMapping("/save")
    public ResponseResult insert(@RequestBody AdChannel channel) {
        return service.insert(channel);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改频道列表", notes = "修改时  会校验:频道id为空,频道名称不能大于10个字符,频道名称不能重复")
    public ResponseResult update(@RequestBody  AdChannel channel) {
        return service.update(channel);
    }

    @GetMapping("/del/{id}")
    @ApiOperation(value = "删除频道列表", notes = " 如果 频道有效  不能删除 ")
    public ResponseResult delete(@PathVariable Integer id) {
        return service.delete(id);
    }

    @ApiOperation("自媒体查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = service.list();
        return ResponseResult.okResult(list);
    }

    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return ResponseResult.okResult(service.getById(id));
    }
}
